From: Colin Walters Date: Thu, 12 Feb 2015 14:13:30 +0000 (-0500) Subject: Add an API to set/unset a deployment tree's mutability X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~806 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=42744628b3bce512e6024ca79804e50275bf1a04;p=ostree.git Add an API to set/unset a deployment tree's mutability This will be used by rpm-ostree to unset the immutable bit temporarily in order to do package layering. We could add an API to deploy a tree without the immutable bit, but this is simpler. --- diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c index 4d59a035..142a9fcc 100644 --- a/src/libostree/ostree-sysroot-deploy.c +++ b/src/libostree/ostree-sysroot-deploy.c @@ -1829,8 +1829,8 @@ ostree_sysroot_deploy_tree (OstreeSysroot *self, cancellable, error)) goto out; - if (!_ostree_linuxfs_alter_immutable_flag (new_deployment_path, TRUE, - cancellable, error)) + if (!ostree_sysroot_deployment_set_mutable (self, new_deployment, FALSE, + cancellable, error)) goto out; { ostree_cleanup_sepolicy_fscreatecon gpointer dummy = NULL; @@ -1927,3 +1927,39 @@ ostree_sysroot_deployment_set_kargs (OstreeSysroot *self, out: return ret; } + +/** + * ostree_sysroot_deployment_set_mutable: + * @self: Sysroot + * @deployment: A deployment + * @mutable: Whether or not deployment's files can be changed + * @error: Error + * + * By default, deployment directories are not mutable. This function + * will allow making them temporarily mutable, for example to allow + * layering additional non-OSTree content. + */ +gboolean +ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, + OstreeDeployment *deployment, + gboolean mutable, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + g_autofree char *deployment_path = ostree_sysroot_get_deployment_dirpath (self, deployment); + glnx_fd_close int fd = -1; + + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; + + if (!glnx_opendirat (self->sysroot_fd, deployment_path, TRUE, &fd, error)) + goto out; + + if (!_ostree_linuxfs_fd_alter_immutable_flag (fd, !mutable, cancellable, error)) + goto out; + + ret = TRUE; + out: + return ret; +} diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h index 54203f19..4342470f 100644 --- a/src/libostree/ostree-sysroot.h +++ b/src/libostree/ostree-sysroot.h @@ -96,6 +96,12 @@ gboolean ostree_sysroot_deploy_tree (OstreeSysroot *self, GCancellable *cancellable, GError **error); +gboolean ostree_sysroot_deployment_set_mutable (OstreeSysroot *self, + OstreeDeployment *deployment, + gboolean mutable, + GCancellable *cancellable, + GError **error); + OstreeDeployment *ostree_sysroot_get_merge_deployment (OstreeSysroot *self, const char *osname);